package swing.project.standard;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * @Title: ExcelUtils.java
 * @Description: TODO(添加描述)
 * @author H819
 * @date 2010-10-24
 * @version V1.0
 */
public class ExcelUtils {

	public void writeExcel() {
		// create a new workbook
		Workbook wb = new HSSFWorkbook();
		// create a new sheet
		Sheet s = wb.createSheet("new sheet");
		// declare a row object reference
		Row r = null;
		// declare a cell object reference
		Cell c = null;

		// create a sheet with 30 rows (0-29)
		int rownum;
		for (rownum = (short) 0; rownum < 30; rownum++) {
			// create a row
			r = s.createRow(rownum);
			// create 10 cells (0-9) (the += 2 becomes apparent later
			for (short cellnum = (short) 0; cellnum < 10; cellnum += 2) {
				c = r.createCell(cellnum);

				c.setCellValue("");
			}
		}

		try {
			FileOutputStream out = new FileOutputStream("d:\\workbook.xls");
			wb.write(out);
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
